import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author ml
 * @create 2017-07-29--9:03
 */
public class Uniestate {


    private static Properties prop=new Properties();
    private String basePath;
    private String pfuserName;
    private String estateName;
    private String dataBaseIp;
    private String serverIp;
    public Uniestate(String basePath, String pfuserName, String estateName, String dataBaseIp, String serverIp){
        this.basePath= basePath;
        this.pfuserName=pfuserName;
        this.estateName=estateName;
        this.dataBaseIp=dataBaseIp;
        this.serverIp=serverIp;



    }



    public void loadProperties() throws IOException {
        prop.load(new FileInputStream(basePath+FilePathEnum.UNIESTATE_PROPERTY.getValue()));

        changeProperties();

    }

    private void changeProperties() throws IOException {

        prop.setProperty("ue.jdbc.username",estateName);
        prop.setProperty("ue.jdbc.url","jdbc:oracle:thin:@"+dataBaseIp+":1521:orcl");
        prop.setProperty("ue.ftp.url",serverIp);

        prop.setProperty("ue.rabbitmq.url",serverIp);

        prop.setProperty("ue.WFServiceUrl.url","http://"+serverIp+":8080/WFService/engine/");

        prop.setProperty("ue.msgServiceUrl.url","http://"+serverIp+":8080/MsgService/message/");

        prop.setProperty("ue.spring.security.cas.serviceProperties.service","http://"+serverIp+":8080/UniEstate/j_spring_cas_security_check");

        prop.setProperty("ue.spring.security.cas.casAuthenticationEntryPoint.loginUrl","http://"+serverIp+":8080/cas/login");

        prop.setProperty("ue.spring.security.cas.ticketValidator.url","http://"+serverIp+":8080/cas");

        prop.setProperty("ue.spring.securuty.cas.logout.success.url","http://"+serverIp+":8080/PFFrame");

        FileOutputStream fos = new FileOutputStream(basePath+FilePathEnum.UNIESTATE_PROPERTY.getValue());
        prop.store(fos, null);
        fos.close();

    }


}
